package com.itheima.mianshi.select;

public class SelectSort {
    public static void main(String[] args) {
        int[] a = {1, 3, 2, 5, 4, 6, 7, 8, 9, 10};
        select(a);
//        for (int i : a) {
//            System.out.print(i + " ");
//        }
    }

    /**
     * 选择排序
     *
     * @param array
     */
    public static void select(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[min] > array[j]) {
                    min = j;
                }
            }
            if (min != i) {
                int temp = array[i];
                array[i] = array[min];
                array[min] = temp;
            }
            System.out.println("第" + (i + 1) + "轮排序后的数组" + java.util.Arrays.toString(array));
        }
    }
}
